\documentclass[12pt]{article}

\usepackage[T1]{fontenc}
\usepackage[letterpaper]{geometry}
\usepackage{hyperref}
\usepackage{parskip}
\usepackage[version=3]{mhchem} % Chemical equation display

\usepackage{svn-multi}
\svnidlong
{$LastChangedBy: ben.trettel $}
{$LastChangedRevision: 9 $}
{$LastChangedDate: 2013-01-20 03:44:53 +0000 (Sun, 20 Jan 2013) $}
{$HeadURL: http://medos.googlecode.com/svn/trunk/doc/plans.tex $}

\title{Plan for health tracking software}
\author{Andrew Trettel and Ben Trettel}

% The following metadata will show up in the PDF properties
\hypersetup{
  colorlinks = false,
  urlcolor = black,
  pdfauthor = {Andrew Trettel and Ben Trettel},
  pdfkeywords = {Health tracking software},
  pdftitle = {},
  pdfsubject = {},
  pdfpagemode = UseNone
}

\begin{document}

\maketitle

\section{Overview and motivation}

The goal is to develop a software API for diet, nutrition, and exercise tracking and modeling.  This is similar to training diary software and diet/nutrition software, but combined.

Similar fitness software is online, like MyFitnessPal and FitDay, but the data isn't private and is kept on a remote server.  A lot of this data is personal, and often the software limits what information the user can get about their data.  These reasons alone inform the decision to make an open-source and local version of this software than can be extended however needed.


% List how you'd like it to be made.
\subsection{Design goals}

\begin{itemize}
\item Limit arbitrariness
   \begin{itemize}
   \item Try to base things off research.  Something probably exists already that could help organize and inform each part.  Back up assumptions with peer-reviewed research.
   \end{itemize}
\item Quantity uncertainty
   \begin{itemize}
   \item Build it from the start to quantity uncertainties in all measurements and calculations.
   \end{itemize}
\item Human-readable text files
   \begin{itemize}
   \item One interface to add meals should just be to type it in a certain format in a plain text file.
   \end{itemize}
\item Transparency
   \begin{itemize}
   \item List sources for data (for example, the total calories and composition for this food came from this database; the calories burned for this exercise is from this calculation).  This lets you sort out if data is user-entered and its provenance.
   \item Do this for every number.  Where does it come from?  Why is it this way?  For example, list the source for the total calories needed in a day or for the RDA of a specific nutrient.  Where does this information come from?  Why should I listen?
   \item The source is also like a credit.  We'll credit where we get information from.
   \end{itemize}
\item Open platform and framework
   \begin{itemize}
   \item Use it as you wish, not as I make you.  You don't have to you it the way I intend it to be used.
   \item This includes binding to let you use it in your own scripts, like Cantera.
   \end{itemize}
\end{itemize}

% What will be the underlying structure to implement all this?
\section{API}

The API will have object-oriented components and procedural components.  The object oriented components will be physical objects and actions that contain data.  The procedures will manipulate the data and model various physical processes.

Based on the following sections, it would be easy to implement this through Python.

% Switch to listings later
\begin{verbatim}
life = importLife("file.life")
life.plotCalories()
\end{verbatim}

\section{Objects}

\subsection{Diet, health, and nutrition}

\begin{description}

\item[Life] This object contains several days and some identifying information.  This object serves as the overall framework for the food and training diaries.  Anything that can be recorded daily can go in here.
   \begin{itemize}
   \item Data
      \begin{itemize}
      \item Name
      \item Gender
      \item Birth date
      \end{itemize}
   \item Methods
      \begin{itemize}
      \item Get day by date
      \item Get any idea of data to plot in time
      \end{itemize}
   \end{itemize}

\item[Day]  This object contains and entire day --- including all meals, exercise and medicine.  It  should be designed to allow easy access to all of its constituents, and allow easy calculation of totals.
   \begin{itemize}
   \item Data
      \begin{itemize}
      \item Date
      \item Array of meals and exercise
      \item Date/Age
      \item Weight
      \item Height
      \item Body composition (mass, body fat percentage, height, waist perimeter)
      \item Heart rate (resting or training)
      \item Array of additional values: hours of sleep during night (time when you went to sleep), shaved or not, etc.
      \end{itemize}
   \item Methods
      \begin{itemize}
      \item All methods for Meal
      \end{itemize}
   \end{itemize}

\item[Meal]
   \begin{itemize}
   \item Data
      \begin{itemize}
      \item Array of foods
      \item Label
      \item Time of meal
      \end{itemize}
   \item Methods
      \begin{itemize}
      \item All methods for Food
      \end{itemize}
   \end{itemize}

\item[Food]
   \begin{itemize}
   \item Data
      \begin{itemize}
      \item Array of compounds, like vitamins, minerals, fat, carbs, and their daily values
      \end{itemize}
   \item Methods
      \begin{itemize}
      \item Get total mass
      \item Get total volume
      \item Get density
      \item Get total calories
      \item Get total carbohydrates by mass and calories
      \item Get total fat by mass and calories
      \item Get total protein by mass and calories
      \end{itemize}
   \item Static methods % Here until I have a better idea.
      \begin{itemize}
      \item Import food from food database
      % http://forum.quantifiedself.com/thread-food-database
      % http://ndb.nal.usda.gov/
      % http://nut.sourceforge.net/
      \end{itemize}
   \item Derived classes: Water, Drink, Alcohol
   \end{itemize}

\item[Medicine]
   \begin{itemize}
   \item Dose
   \end{itemize}

\end{description}

\subsection{Exercise}

\begin{description}

\item[Workout]
   \begin{itemize}
   \item Data
      \begin{itemize}
      \item Array of exercise and breaks
      \item Time of workout
      \end{itemize}
   \item Methods
      \begin{itemize}
      \item All the methods for Exercise
      \end{itemize}
   \end{itemize}
\item[Exercise]
   \begin{itemize}
   \item Data
      \begin{itemize}
      \item Amount of exercise
      \end{itemize}
   \item Methods
      \begin{itemize}
      \item Get calories burned
      % Compendium of Physical Activities
      % https://sites.google.com/site/compendiumofphysicalactivities/
      % https://en.wikipedia.org/wiki/Metabolic_equivalent
      \item Get water used
      % Try to estimate how much water you lose from a workout.  You can lose it by sweating and other ways.  Also try to estimate if a particular activity uses specific vitamins.  Record sweat? Is there a good way to estimate how much you swear during a workout?
      % http://fitness.stackexchange.com/questions/6984/reduce-sweat-rate
      \end{itemize}
   \item Derived classes
      \begin{itemize}
      \item Running
      \item Break
      \item Lifting
      \end{itemize}
   \end{itemize}

\item[Running]
   \begin{itemize}
   \item Data
      \begin{itemize}
      \item Shoe used during run
      \end{itemize}
   \item Methods
      \begin{itemize}
      \item Import from pedometer
      \item Import from GPS.  Import the path, time, elevation, and speed data.
      \item Import heart rate monitor data.
      \item Predict how many calories were burned.  This can be done before and after the run.  For a before case, you should be able to predict how many calories you should need for a particular race given a particular pace.
      \item Get total $V \ce{O_2}$
      \item Get aerobic $V \ce{O_2}$
      \item Get anaerobic $V \ce{O_2}$
      \item Get average speed
      \item Get total duration
      \item Get maximum speed
      \item Get minimum speed
      \end{itemize}
   \end{itemize}

\item[Bicycling]
   \begin{itemize}
   \item Methods
      \begin{itemize}
      \item Import from bike computer
      \end{itemize}
   \end{itemize}

\item[Shoe]
   \begin{itemize}
   \item Data
      \begin{itemize}
      \item Label
      \item Date purchased
      \item Accumulated miles
      \item Active or inactive?  Are you still using these shoes, or are they too old?
      \item List of runs done with this shoe?  This might stretch the capabilities.
      \end{itemize}
   \item Methods
      \begin{itemize}
      \item Add miles based on workout.
      \item Estimate remaining life.
      \end{itemize}
   \end{itemize}

\end{description}


\section{Modules}


\subsection{BodyCompositionModels}

These models predict body mass for particular diets and exercise regimens.  Functions are provided to calibrate the models as well.
\begin{itemize}
   \item Use daily weight, exercise, and food intake data to calibrate (optimize) model for weight.  Use model to predict future weight given a specific diet.  Try to predict body mass and composition.
   % using conservation of energy and mass, derive equations for total body mass, body fat percentage, body muscle percentage, poop/pee mass flow rate, etc.
   % http://fitness.stackexchange.com/questions/262/how-to-calculate-body-fat
\end{itemize}

\subsection{DietDesign}

Tools to help design a diet for particular goals.
\begin{itemize}
\item Model a diet for particular (possibly simultaneous) goals:
   \begin{itemize}
   \item Nutritional needs (what your previous diet lacks)
   \item Predicted weight in the future.  This answers the questions ``What should I eat or do to weight 10 lbs less in 3 months?''  It's a backwards problem, but it is likely solvable.
   \item Diabetic (control blood glucose)
   \item Specialized diet (vegan, food allergies, religious restrictions, etc.)
   \end{itemize}
% Food suggestions.  Optimize using a utility function.  The suggestions could be based on personal preferences (Pandora-style thumbs-up or thumps-down), expiration dates (eat food before it expires), what you diet lacks, and budget (for minimum healthy diet or best diet), what you have coupons for, what's on sale, what's been recalled, tax-free days.  Design for people with specific diets: calorie restriction, food allergies, religious restrictions, diabetes, vegans, environmentalists.
\end{itemize}

% This doesn't seem right, though.
\subsection{DietModels}

Models for a correct and balanced diet.  Based on weight, height, and other needs.
\begin{itemize}
\item RDAs (recommended daily allowances)
% fiber
% https://www.ncbi.nlm.nih.gov/pubmed/19335713
% "The recommended dietary fiber intakes for children and adults are 14 g/1000 kcal."
% https://www.mayoclinic.com/health/fiber/NU00033/NSECTIONGROUP=2
% https://en.wikipedia.org/wiki/Dietary_fiber#Guidelines_on_fiber_intake
\end{itemize}

\subsection{HeartRateKineticsModels}

These models predict heart rate kinetics.  Functions are provided to calibrate the models as well.  Heart rate kinetics are easy to measure.  I think this can be correlated to $\dot{V} \ce{O_2}$ kinetics, so it should contain a conversion function.

\subsection{MaximumRateModels}

These models predict the maximum rates at which the body operates, including maximum heart rate and ${\dot{V} \ce{O_2}}_\text{max}$.

\subsection{RestingRateModels}

These models predict the number of calories needed to live.  These models should also include models for resting $\dot{V} \ce{O_2}$.
\begin{itemize}
\item Calculate basal metabolic rate and daily calories needed.

% Frankenfield 2005
According to Frankenfield, the best resting energy expenditure model is the Mifflin-St.\ Jeor equations: % Mifflin 1990, p. 246

\begin{equation}
   REE = \left ( \frac{9.99 m}{1~\text{kg}} + \frac{6.25 h}{1~\text{cm}} - \frac{4.92 t}{1~\text{year}} + s \right ) \frac{\text{kcal}}{\text{day}}
\end{equation}

$s = -161$ for men and $s = 5$ for women.

Another commonly used equation is the Revised Harris-Benedict Equation: % Roza 1984, p. 171

\begin{equation}
   REE_\text{men} = \left ( 88.362 + \frac{4.799 h}{1~\text{cm}} + \frac{13.397 m}{1~\text{kg}} - \frac{5.677 t}{1~\text{year}} \right ) \frac{\text{kcal}}{\text{day}}
\end{equation}

\begin{equation}
   REE_\text{women} = \left ( 447.593 + \frac{3.098 h}{1~\text{cm}} + \frac{9.247 m}{1~\text{kg}} - \frac{4.737 t}{1~\text{year}} \right ) \frac{\text{kcal}}{\text{day}}
\end{equation}
      
Many sites use an additional fudge factor (activity factor) to account for lifestyle to arrive at the total daily energy expenditure.

\begin{equation}
   TDEE = f REE
\end{equation}

\begin{table}
\centering
\begin{tabular}{l | c c}
Lifestyle      & Durnin and Passmore 1967 & WHO 1985 \\
\hline
Sedentary      & 1.0 & 1.2 \\
Lightly active    & 1.5 & 1.375 \\
Moderately active & 2.5 & 1.55 \\
Very active    & 5.0 & 1.725 \\
Extra active      & 7.0 & 1.9 \\
\end{tabular}
\caption{Activity factors $f$ for various lifestyles}
\end{table}

These are commonly used, but are considered inaccurate.  For one, they were developed decades ago from even older data, and may not represent modern life well.  Second, it would be more accurate to account for you activity and use actual exercise values for each day, resulting in a much more accurate value that can change from day to day.  It would probably be reasonable to use the WHO values for a sedentary or lightly active lifestyle, and to then add calories based on the day's activities.

% WHO 2001 discusses this (they call $f$ PAL) around p. 35.  They also have a lot of more modern factors in that section.
% The WHO 1985 factors are provided here:
% This is similar to the Harris Benedict formula, and the activity factors found at
% http://gottasport.com/weight-loss/71/harris-benedict-formula-for-women-and-men.html
% https://doctorholmes.wordpress.com/2011/01/27/losing-weight-with-basal-metabolic-rate-the-mifflin-st-jeor-method/
% http://www.scientificpsychic.com/health/cron1.html
% http://forums.johnstonefitness.com/archive/index.php/t-13910.html
% http://www.fao.org/docrep/003/AA040E/AA040E06.htm#ch6
% http://www.myfitnesspal.com/topics/show/689733-what-is-my-activity-level
% http://www.quickbmr.com/what-is-tdee.html
% http://calorieline.com/tools/tdee

\item Calculate the resting $\dot{V} \ce{O_2}$.  This number is useful for oxygen uptake kinetics models.

Roza, which has a model for resting energy expenditure, also has a model for resting oxygen consumption (in mL/min): % Roza 1984, p. 177

\begin{equation}
   {\dot{V} \ce{O_2}}_\text{men} = \left ( 12.04 + \frac{0.687 h}{1~\text{cm}} + \frac{1.929 m}{1~\text{kg}} - \frac{0.802 t}{1~\text{year}} \right ) \frac{\text{mL}}{\text{min}}
\end{equation}

\begin{equation}
   {\dot{V} \ce{O_2}}_\text{women} = \left ( 63.23 + \frac{0.457 h}{1~\text{cm}} + \frac{1.318 m}{1~\text{kg}} - \frac{0.621 t}{1~\text{year}} \right ) \frac{\text{mL}}{\text{min}}
\end{equation}
\end{itemize}

\subsection{TrainingImprovementModels}

Tools to quantify if you are overtraining, undertraining, or training well.  The goal is to simulate the response to running training and to simulate exercise performance improvement
\begin{itemize}
\item Use a model to predict the body's response to training.  Will this training lead to overtraining, undertraining, or will it allow you to peak at just the right time?  This removes the arbitrariness in the planning.
% http://www.letsrun.com/forum/flat_read.php?thread=4811308
% http://www.springerlink.com/content/mt41146862226123/
% Injury: http://www.sciencedaily.com/releases/2010/02/100216221303.htm
\item Recovery model --- determine how much energy is used during workout and how many hours after workout you should be back up to 100 percent.
\end{itemize}

\subsection{VdotO2DemandModels}

These models predict the $\dot{V} \ce{O_2}$ demand curve for particular activities, like running at a particular velocity at certain times.  In running, this curve is called the running economy curve.

A simple one would be a linear one, which is mostly correct for sub-maximal work.  At $v = 0$, it would be at ${\dot{V} \ce{O_2}}_\text{min}$; at $v = v{\dot{V} \ce{O_2}}_\text{max}$, it would be at ${\dot{V} \ce{O_2}}_\text{max}$.

\subsection{VdotO2KineticsModels}

These models predict $\dot{V} \ce{O_2}$ kinetics for a particular demand curve, which could be based on running or biking.  Functions are provided to calibrate the models as well.  $\dot{V} \ce{O_2}$ kinetics are hard to measure, so these models will be based on several assumptions.

The overall goal of these models is to simulate the aerobic/anaerobic portions of running.

There should be an option to calibrate the models from heart rate data, since it's related to $\dot{V} \ce{O_2}$ data.

The Stirling model is the most useful one at the moment, given that it allows for variable speeds and $\dot{V} \ce{O_2}$ drift: % Stirling 2004, p. 1000

\begin{equation}
   \frac{d{\dot{V} \ce{O_2}}}{dt} = A
   \left ( {\dot{V} \ce{O_2}} - {\dot{V} \ce{O_2}}_\text{min} \right )^B
   \left ( {\dot{V} \ce{O_2}}_\text{max} - {\dot{V} \ce{O_2}} \right )^C
   \left ( D(v,t) - {\dot{V} \ce{O_2}} \right )^E
\end{equation}

${\dot{V} \ce{O_2}}_\text{min}$ can come from the the resting oxygen update models.  ${\dot{V} \ce{O_2}}_\text{max}$ can come from the several models.  The demand curve can come from the demand models, and if possible can model $\dot{V} \ce{O_2}$ drift.  The values $A$, $B$, $C$, and $E$ will have to be calibrated, though.  A constraint is the $E$ must be an odd integer, because it must be able to go negative is demand is below uptake, since demand will follow uptake.

% The Stirling model is more general and has much more predictive value.  The three-phase model is of theoretical interest, though neither are ultimately derived from first principles.  They more of less just fit the data.

\subsection{WorkoutDesign}

Tools to help design workout for particular goals.  For example, design a workout with at least 10 minutes at 400 m/min, or design a workout with at least 10 minutes at above 95 percent ${\dot{V} \ce{O_2}}_\text{max}$.
\begin{itemize}
\item Use $\dot{V} \ce{O_2}$ kinetics for predict optimal break time and rep time for ${\dot{V} \ce{O_2}}_\text{max}$ training.
\item The goal is to use the oxygen uptake kinetics model to design workouts to achieve particular goals.  There is no guesswork; if the model is correct, running at those speeds at those times with those breaks will have this effect on your body.  For example, if designed correctly, it can develop a maximal oxygen uptake training workout to get 10 minutes at VdotO2max, or something like that.
\end{itemize}


\end{document}
